<?php
require_once "settings.php";
require_once 'DbSimple/Generic.php';
//require_once '../add/TegGenerator.php';

//Ссылки на все страницы проекта
$proj_editor = $url.'/php/projects/editor.php';
$projs = $url.'/php/projects/modul.php';
$groups = $url.'/php/groups/modul.php';
$groups_settings = $url.'/php/groups_settings/modul.php';
$monitor = $url.'/oldmonitor/index2.php';
$new_monitor=$url.'/php/monitor/modul.php';
$trh = 'style="height:25;"';


if (isset($_POST['variable']))
{
	$v = $_POST['variable'];

	
	
	switch ($v)
	{
		case 'projs': echo $projs;
		break;
		case 'proj_editor': echo $proj_editor;
		break;
		case 'groups': echo $groups;
		break;
		case 'groups_settings': echo $groups_settings;
		break;
		case 'monitor': echo $monitor;
		break;
		case 'url': echo $url;
		break;
		case 'now':
		$dnow = new DateTime("now");
		echo $dnow->format('Y-m-d H:i:s');
		break;
		case 'minday':
			echo minday();
			break;
		case 'maxday':
			echo maxday();
			break;
		default:
		$res = getvar($v);
		echo $res;
		break;
	}
	
}

function minday()
{
	global$host;
	global$login;
	global$pass;
	global$bdname;
	$mydbh = DbSimple_Generic::connect("mysql://$login:$pass@$host/$bdname");
	$mydbh->query('SET NAMES utf8');
	$stat_dt1 = $mydbh->select('SELECT MIN(`datetime`) as `min_date` FROM `stat_in_days`');
	$d1 = new DateTime('now');
	$d1->d=1;
	if( isset($stat_dt1[0]['min_date']) ) 
		$d1 = new DateTime($stat_dt1[0]['min_date']);
	return $d1->format("Y-m-d");
}

function maxday()
{
	global$host;
	global$login;
	global$pass;
	global$bdname;
	$mydbh = DbSimple_Generic::connect("mysql://$login:$pass@$host/$bdname");
	$mydbh->query('SET NAMES utf8');
	$stat_dt2 = $mydbh->select('SELECT MAX(`datetime`) as `max_date` FROM `stat_in_days`');
	$d2 = new DateTime('now');
	if( isset($stat_dt2[0]['max_date']) )
		$d2 = new DateTime($stat_dt2[0]['max_date']);
	return $d2->format("Y-m-d");
}

function tabs()
{
	global$monitor;
	global$groups;
	global$projs;
	global$groups_settings;
	global$new_monitor;

	echo	'<div id="tabs">

			<ul class="tabContainer">
			<!-- The jQuery generated tabs go here -->
			</ul>
			
			<div class="clear">
				
			</div>

		</div>';
	echo '<div style="height:5px; width:100%;"></div>';
}

function setvar($name, $value)
{
	global$host;
	global$login;
	global$pass;
	global$bdname;
	$mydbh = DbSimple_Generic::connect("mysql://$login:$pass@$host/$bdname");
	$mydbh->query('SET NAMES utf8');
	$row = array();
	$row['name'] = $name;
	$row['value'] = $value;
	$mydbh->query('INSERT INTO vars(?#) VALUES(?a) ON DUPLICATE KEY UPDATE value = ?',array_keys($row),array_values($row),$value);
}

function getvar($name)
{
	global$host;
	global$login;
	global$pass;
	global$bdname;
	$mydbh = DbSimple_Generic::connect("mysql://$login:$pass@$host/$bdname");
	$mydbh->query('SET NAMES utf8');
	$rows1 = $mydbh->select('SELECT * FROM vars WHERE name=?', $name);
	if (count($rows1)>0)
		$value = $rows1[0]['value'];
	else
		$value = '';
	return $value;
}

function dbconn()
{
	global$host;
	global$login;
	global$pass;
	global$bdname;
	
		 $conn = mysql_connect ($host, $login, $pass)or die ("Соединение не установлено!");
		 mysql_select_db($bdname) or die ("База не найдена!");
		 mysql_query('SET NAMES utf8');
		 return $conn;
}
///////////////head-function

function head_ed_p()
{
	global$url;
	
	echo '<head>
	<meta http-equiv="Content-Type" content="text/html; Charset=UTF-8"> </meta>
		<script src="'.$url.'/js/jquery-1.6.2.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="'.$url.'/js/jquery-ui-1.8.16.custom.min.js"></script>
		<script type="text/javascript" src="http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-ru.js"></script>
		<title>Статистика по входящим</title>
		<link rel="stylesheet" type="text/css" href="'.$url.'/tabs/styles.css" />
		<script type="text/javascript" src="'.$url.'/tabs/script.js"></script>
		<script>
			$(function() {
				$(".datepicker" ).datepicker(
				{
				dateFormat: "yy-mm-dd"
				});
				$( ".datepicker" ).datepicker( $.datepicker.regional[ "ru" ] );
			});
		</script>

		<style type="text/css">
			/*demo page css*/
			body{ font: 62.5% "Trebuchet MS", sans-serif;}
			.demoHeaders { margin-top: 2em; }
			#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
			#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
			ul#icons {margin: 0; padding: 0;}
			ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
			ul#icons span.ui-icon {float: left; margin: 0 4px;}
		</style>
		<script src="'.$url.'/js/edit_projects.js" type="text/javascript"></script>
		<link type="text/css" href="'.$url.'/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />		
		<link type="text/css" href="'.$url.'/css/button.css" rel="stylesheet" />	
	 </head>';
}

function head_g()//для групп 
{
	global$url;
	echo '<head>
	<meta http-equiv="Content-Type" content="text/html; Charset=UTF-8"> </meta>
		<script src="'.$url.'/js/jquery-1.6.2.min.js" type="text/javascript"></script>
		<script src="'.$url.'/js/groups.js" type="text/javascript"></script>
		<script type="text/javascript" src="'.$url.'/js/jquery-ui-1.8.16.custom.min.js"></script>
		<title>Статистика по входящим</title>
		<link rel="stylesheet" type="text/css" href="'.$url.'/tabs/styles.css" />
		<script type="text/javascript" src="'.$url.'/tabs/script.js"></script>
		<style type="text/css">
			/*demo page css*/
			body{ font: 62.5% "Trebuchet MS", sans-serif;}
			.demoHeaders { margin-top: 2em; }
			#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
			#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
			ul#icons {margin: 0; padding: 0;}
			ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
			ul#icons span.ui-icon {float: left; margin: 0 4px;}
		</style>
		<link type="text/css" href="'.$url.'/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		<link type="text/css" href="'.$url.'/css/groups_and_projects.css" rel="stylesheet" />	
		<link type="text/css" href="'.$url.'/css/button.css" rel="stylesheet" />	
	 </head>';
}

function head_p()//для проектов
{
	global$url;
	echo '<head>
	<meta http-equiv="Content-Type" content="text/html; Charset=UTF-8"> </meta>
		<script src="'.$url.'/js/jquery-1.6.2.min.js" type="text/javascript"></script>
		<script src="'.$url.'/js/projects.js" type="text/javascript"></script>
		<script type="text/javascript" src="'.$url.'/js/jquery-ui-1.8.16.custom.min.js"></script>
		<title>Статистика по входящим</title>
		<link rel="stylesheet" type="text/css" href="'.$url.'/tabs/styles.css" />
		<script type="text/javascript" src="'.$url.'/tabs/script.js"></script>
		<style type="text/css">
			/*demo page css*/
			body{ font: 62.5% "Trebuchet MS", sans-serif;}
			.demoHeaders { margin-top: 2em; }
			#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
			#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
			ul#icons {margin: 0; padding: 0;}
			ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
			ul#icons span.ui-icon {float: left; margin: 0 4px;}
		</style>
		<link type="text/css" href="'.$url.'/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		

		<link type="text/css" href="'.$url.'/css/groups_and_projects.css" rel="stylesheet" />
		<link type="text/css" href="'.$url.'/css/button.css" rel="stylesheet" />	
	 </head>';
}

function head_mon()
{
	global$url;
	echo '<head>
	<meta http-equiv="Content-Type" content="text/html; Charset=UTF-8"> </meta>
		<script src="'.$url.'/js/jquery-1.6.2.min.js" type="text/javascript"></script>
		<script src="'.$url.'/js/monitor.js" type="text/javascript"></script>
		<script src="'.$url.'/js/my_lib.js" type="text/javascript"></script>
		<script type="text/javascript" src="'.$url.'/js/jquery-ui-1.8.16.custom.min.js"></script>
		<link type="text/css" href="'.$url.'/css/monitor.css" rel="stylesheet" />	
		<link type="text/css" href="'.$url.'/css/button.css" rel="stylesheet" />	
	 </head>';
}

function head_gs()
{
	global$url;
	echo '<head>
	<meta http-equiv="Content-Type" content="text/html; Charset=UTF-8"> </meta>
		<script src="'.$url.'/js/jquery-1.6.2.min.js" type="text/javascript"></script>
		<script src="'.$url.'/js/groups_settings.js" type="text/javascript"></script>
		<title>Статистика по входящим</title>
		<link rel="stylesheet" type="text/css" href="'.$url.'/tabs/styles.css" />
		<script type="text/javascript" src="'.$url.'/tabs/script.js"></script>
		<script type="text/javascript" src="'.$url.'/js/jquery-ui-1.8.16.custom.min.js"></script>
		<style type="text/css">
			/*demo page css*/
			body{ font: 62.5% "Trebuchet MS", sans-serif;}
			.demoHeaders { margin-top: 2em; }
			#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
			#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
			ul#icons {margin: 0; padding: 0;}
			ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
			ul#icons span.ui-icon {float: left; margin: 0 4px;}
		</style>
		<link type="text/css" href="'.$url.'/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		
				<!--[if IE]>
					<link rel="stylesheet" href="'.$url.'/css/ie.css" type "text/css" media="screen">
				<![endif]-->
		
		<link type="text/css" href="'.$url.'/css/groups_settings.css" rel="stylesheet" />	
		<link type="text/css" href="'.$url.'/css/button.css" rel="stylesheet" />	
	 </head>';
}
?>